package com.hcb.tonguetiphealth.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hcb.tonguetiphealth.model.Wine;
import com.hcb.tonguetiphealth.view.R;

public class DrinksBookDialogListAdapter extends BaseAdapter {

	private Context mContext;
	private List<Wine> mList;
	private LayoutInflater vi;
	
	public DrinksBookDialogListAdapter(Context context,List<Wine> list) {
		mContext = context;
		mList = list;
	}
	
	public int getCount() {
		if(mList == null) {
			return 0;
		}
		return mList.size();
	}
	
	public Object getItem(int position) {
		if(mList == null) {
			return null;
		} else {
			return mList.get(position);
		}
	}
	
	public long getItemId(int position) {
		return position;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {

		View view;
		
		if(convertView == null) {
			vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = (LinearLayout) vi.inflate(R.layout.drinks_book_dialog_list_item, null);
		} else {
			view = convertView;
		}
		FillDataIntoView(view, position);
		
		return view;
	}
	
	private void FillDataIntoView(View view, int position) {
		final Wine wine = mList.get(position);

		TextView tv_ = (TextView)view.findViewById(R.id.drinks_book_dialog_item_textview);
		tv_.setText(wine.getName());
	}
}
